﻿using System;

namespace Communication.Message.Buffer
{
	// Token: 0x0200000A RID: 10
	internal abstract class AbstractMessageBuffer : MessageBuffer
	{
		// Token: 0x06000053 RID: 83 RVA: 0x00002226 File Offset: 0x00000426
		public int ReaderIndex()
		{
			return this.readerIndex;
		}

		// Token: 0x06000054 RID: 84 RVA: 0x0000222E File Offset: 0x0000042E
		public int WriterIndex()
		{
			return this.writerIndex;
		}

		// Token: 0x06000055 RID: 85 RVA: 0x00002236 File Offset: 0x00000436
		public void SetIndex(int readerIndex, int writerIndex)
		{
			if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > this.Capacity())
			{
				throw new IndexOutOfRangeException();
			}
			this.readerIndex = readerIndex;
			this.writerIndex = writerIndex;
		}

		// Token: 0x06000056 RID: 86 RVA: 0x0000225D File Offset: 0x0000045D
		public void ReaderIndex(int readerIndex)
		{
			if (readerIndex < 0 || readerIndex > this.writerIndex)
			{
				throw new IndexOutOfRangeException();
			}
			this.readerIndex = readerIndex;
		}

		// Token: 0x06000057 RID: 87 RVA: 0x00002279 File Offset: 0x00000479
		public void WriterIndex(int writerIndex)
		{
			if (writerIndex < this.readerIndex || writerIndex > this.Capacity())
			{
				throw new IndexOutOfRangeException();
			}
			this.writerIndex = writerIndex;
		}

		// Token: 0x06000058 RID: 88 RVA: 0x0000229A File Offset: 0x0000049A
		public bool Readable()
		{
			return this.ReadableBytes() > 0;
		}

		// Token: 0x06000059 RID: 89 RVA: 0x000022A5 File Offset: 0x000004A5
		public bool Writable()
		{
			return this.WritableBytes() > 0;
		}

		// Token: 0x0600005A RID: 90
		public abstract int Capacity();

		// Token: 0x0600005B RID: 91 RVA: 0x000022B0 File Offset: 0x000004B0
		public int ReadableBytes()
		{
			return this.writerIndex - this.readerIndex;
		}

		// Token: 0x0600005C RID: 92 RVA: 0x000022BF File Offset: 0x000004BF
		public int WritableBytes()
		{
			return this.Capacity() - this.writerIndex;
		}

		// Token: 0x0600005D RID: 93 RVA: 0x000022D0 File Offset: 0x000004D0
		public void DiscardReadBytes()
		{
			if (this.readerIndex == 0)
			{
				return;
			}
			this.SetBytes(0, this, this.readerIndex, this.writerIndex - this.readerIndex);
			this.writerIndex -= this.readerIndex;
			this.markedReaderIndex = Math.Max(this.markedReaderIndex - this.readerIndex, 0);
			this.markedWriterIndex = Math.Max(this.markedWriterIndex - this.readerIndex, 0);
			this.readerIndex = 0;
		}

		// Token: 0x0600005E RID: 94 RVA: 0x00002350 File Offset: 0x00000550
		public void Clear()
		{
			this.readerIndex = (this.writerIndex = 0);
		}

		// Token: 0x0600005F RID: 95 RVA: 0x00002370 File Offset: 0x00000570
		public virtual void WriteByte(byte b)
		{
			this.SetByte(this.writerIndex++, b);
		}

		// Token: 0x06000060 RID: 96 RVA: 0x00002395 File Offset: 0x00000595
		public virtual void WriteShort(short s)
		{
			this.SetShort(this.writerIndex, s);
			this.writerIndex += 2;
		}

		// Token: 0x06000061 RID: 97 RVA: 0x000023B2 File Offset: 0x000005B2
		public virtual void WriteUshort(ushort us)
		{
			this.SetUshort(this.writerIndex, us);
			this.writerIndex += 2;
		}

		// Token: 0x06000062 RID: 98 RVA: 0x000023CF File Offset: 0x000005CF
		public virtual void WriteInt(int i)
		{
			this.SetInt(this.writerIndex, i);
			this.writerIndex += 4;
		}

		// Token: 0x06000063 RID: 99 RVA: 0x000023EC File Offset: 0x000005EC
		public virtual void WriteUint(uint ui)
		{
			this.SetUint(this.writerIndex, ui);
			this.writerIndex += 4;
		}

		// Token: 0x06000064 RID: 100
		public abstract void SetByte(int index, byte b);

		// Token: 0x06000065 RID: 101
		public abstract void SetShort(int index, short s);

		// Token: 0x06000066 RID: 102 RVA: 0x00002409 File Offset: 0x00000609
		public void SetUshort(int index, ushort us)
		{
			this.SetShort(index, (short)us);
		}

		// Token: 0x06000067 RID: 103
		public abstract void SetInt(int index, int i);

		// Token: 0x06000068 RID: 104 RVA: 0x00002414 File Offset: 0x00000614
		public void SetUint(int index, uint ui)
		{
			this.SetInt(index, (int)ui);
		}

		// Token: 0x06000069 RID: 105 RVA: 0x00002420 File Offset: 0x00000620
		public byte ReadByte()
		{
			if (this.readerIndex == this.writerIndex)
			{
				throw new IndexOutOfRangeException("no more byte to read.");
			}
			return this.GetByte(this.readerIndex++);
		}

		// Token: 0x0600006A RID: 106 RVA: 0x00002460 File Offset: 0x00000660
		public short ReadShort()
		{
			this.CheckReadableBytes(2);
			short @short = this.GetShort(this.readerIndex);
			this.readerIndex += 2;
			return @short;
		}

		// Token: 0x0600006B RID: 107 RVA: 0x00002490 File Offset: 0x00000690
		public ushort ReadUshort()
		{
			this.CheckReadableBytes(2);
			ushort @ushort = this.GetUshort(this.readerIndex);
			this.readerIndex += 2;
			return @ushort;
		}

		// Token: 0x0600006C RID: 108 RVA: 0x000024C0 File Offset: 0x000006C0
		public int ReadInt()
		{
			this.CheckReadableBytes(4);
			int @int = this.GetInt(this.readerIndex);
			this.readerIndex += 4;
			return @int;
		}

		// Token: 0x0600006D RID: 109 RVA: 0x000024F0 File Offset: 0x000006F0
		public uint ReadUint()
		{
			this.CheckReadableBytes(4);
			uint @uint = this.GetUint(this.readerIndex);
			this.readerIndex += 4;
			return @uint;
		}

		// Token: 0x0600006E RID: 110
		public abstract byte GetByte(int index);

		// Token: 0x0600006F RID: 111
		public abstract short GetShort(int index);

		// Token: 0x06000070 RID: 112 RVA: 0x00002520 File Offset: 0x00000720
		public ushort GetUshort(int index)
		{
			return (ushort)this.GetShort(index);
		}

		// Token: 0x06000071 RID: 113
		public abstract int GetInt(int index);

		// Token: 0x06000072 RID: 114 RVA: 0x0000252A File Offset: 0x0000072A
		public uint GetUint(int index)
		{
			return (uint)this.GetInt(index);
		}

		// Token: 0x06000073 RID: 115 RVA: 0x00002534 File Offset: 0x00000734
		public int ReadBytes(byte[] dst, int dstIndex)
		{
			if (dstIndex < 0 || dstIndex > dst.Length)
			{
				throw new IndexOutOfRangeException();
			}
			int num = (dst.Length - dstIndex > this.ReadableBytes()) ? this.ReadableBytes() : (dst.Length - dstIndex);
			this.GetBytes(this.readerIndex, dst, dstIndex, num);
			this.readerIndex += num;
			return num;
		}

		// Token: 0x06000074 RID: 116
		public abstract void GetBytes(int index, byte[] dst, int dstIndex, int length);

		// Token: 0x06000075 RID: 117 RVA: 0x0000258A File Offset: 0x0000078A
		public virtual void WriteBytes(byte[] src, int srcIndex, int length)
		{
			this.SetBytes(this.writerIndex, src, srcIndex, length);
			this.writerIndex += length;
		}

		// Token: 0x06000076 RID: 118 RVA: 0x000025A9 File Offset: 0x000007A9
		public virtual void WriteBytes(MessageBuffer src, int srcIndex, int length)
		{
			this.SetBytes(this.writerIndex, src, srcIndex, length);
			this.writerIndex += length;
		}

		// Token: 0x06000077 RID: 119
		public abstract void SetBytes(int index, byte[] src, int srcIndex, int length);

		// Token: 0x06000078 RID: 120
		public abstract void SetBytes(int index, MessageBuffer src, int srcIndex, int length);

		// Token: 0x06000079 RID: 121
		public abstract byte[] Array();

		// Token: 0x0600007A RID: 122
		public abstract ByteOrder Order();

		// Token: 0x0600007B RID: 123
		public abstract MessageBufferFactory Factory();

		// Token: 0x0600007C RID: 124 RVA: 0x000025C8 File Offset: 0x000007C8
		public virtual void EnsureWritableBytes(int writableBytes)
		{
			if (writableBytes > this.WritableBytes())
			{
				throw new IndexOutOfRangeException();
			}
		}

		// Token: 0x0600007D RID: 125 RVA: 0x000025D9 File Offset: 0x000007D9
		protected void CheckReadableBytes(int minimumReadableBytes)
		{
			if (this.ReadableBytes() < minimumReadableBytes)
			{
				throw new IndexOutOfRangeException();
			}
		}

		// Token: 0x0600007E RID: 126 RVA: 0x000025EA File Offset: 0x000007EA
		public void MarkReaderIndex()
		{
			this.markedReaderIndex = this.readerIndex;
		}

		// Token: 0x0600007F RID: 127 RVA: 0x000025F8 File Offset: 0x000007F8
		public void ResetReaderIndex()
		{
			this.ReaderIndex(this.markedReaderIndex);
		}

		// Token: 0x06000080 RID: 128 RVA: 0x00002606 File Offset: 0x00000806
		public void MarkWriterIndex()
		{
			this.markedWriterIndex = this.writerIndex;
		}

		// Token: 0x06000081 RID: 129 RVA: 0x00002614 File Offset: 0x00000814
		public void ResetWriterIndex()
		{
			this.WriterIndex(this.markedWriterIndex);
		}

		// Token: 0x06000082 RID: 130 RVA: 0x00002622 File Offset: 0x00000822
		public bool Equals(MessageBuffer messageBuffer)
		{
			return MessageBuffers.Equals(this, messageBuffer);
		}

		// Token: 0x04000003 RID: 3
		private int readerIndex;

		// Token: 0x04000004 RID: 4
		private int writerIndex;

		// Token: 0x04000005 RID: 5
		private int markedReaderIndex;

		// Token: 0x04000006 RID: 6
		private int markedWriterIndex;
	}
}
